package com.efounder.builder.base.data;

import java.util.*;
import java.util.concurrent.*;


import com.efounder.object.*;
import com.efounder.util.AppContext;

/**
 * @author Skyline
 */
public class EFDataSet implements java.io.Serializable, ChildLinkParentKey {
    /**
     *
     */
    static final long serialVersionUID = 1L;
    /**
     *
     */
    protected Object master;
    /**
     *
     */
    private String tableName = null;

    /**
     *
     */
    public String getTableName() {
        return tableName;
    }

    /**
     * @param tableName
     */
    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    /**
     *
     */
    private String parentTableName = null;

    /**
     * @return String
     */
    public String getParentTableName() {
        return this.parentTableName;
    }

    /**
     * @param name String
     */
    public void setParentTableName(String name) {
        this.parentTableName = name;
    }

    /**
     *
     */
    protected EFRowSet parentRowSet = null;

    /**
     * @param rowSet EFRowSet
     */
    public void setParentRowSet(EFRowSet rowSet) {
        this.parentRowSet = rowSet;
    }

    /**
     * @return EFRowSet
     */
    public EFRowSet getParentRowSet() {
        return this.parentRowSet;
    }

    /**
     *
     */
    protected String[] primeKey = null;

    /**
     * @return String[]
     */
    public String[] getPrimeKey() {
        return primeKey;
    }

    /**
     * @param primeKey String
     */
    public void setPrimeKey(String[] primeKey) {
        this.primeKey = primeKey;
    }

    /**
     *
     */
    public EFDataSet() {

    }

    /**
     *
     */
    public static final int _DATA_SET_MAP_ = 0x0000; // 数据映射，啥也不管
    /**
     *
     */
    public static final int _DATA_SET_VIEW_ = 0x0001; // 数据视图，只监听事件，不管理事件
    /**
     *
     */
    public static final int _DATA_SET_CONT_ = 0x0002; // 数据容器，啥也管
    /**
     *
     */
    protected int dataSetType = _DATA_SET_MAP_;

    /**
     * @return int
     */
    public int getDataSetType() {
        return dataSetType;
    }

    /**
     * @param tableName String
     * @return EFDataSet
     */
    public static EFDataSet getInstance(String tableName) {
        return getInstance(tableName, _DATA_SET_MAP_);
    }

    /**
     * @param tableName
     * @return
     */
    public static EFDataSet getInstance(String tableName, int dataSetType) {
        EFDataSet dataSet = new EFDataSet();
        dataSet.dataSetType = dataSetType;
        dataSet.tableName = tableName;
        return dataSet;
    }

    /**
     * @return int
     */
    public final boolean atFirst() {
        return (currentRowIndex == 0);
    }

    /**
     * @return int
     */
    public final boolean atLast() {
        if (rowSetList == null || rowSetList.size() == 0) return true;
        return (currentRowIndex == (rowSetList.size() - 1));
    }

    /**
     * @return int
     */
    public final int first() {
        if (rowSetList == null || rowSetList.size() == 0) return -1;
        // 如果数据为空，则返回-1
        return this.goToRow(0);
    }

    /**
     * @return int
     */
    public final int prior() {
        int rowIndex = currentRowIndex - 1;
        if (rowIndex >= 0)
            return this.goToRow(rowIndex);
        else
            return -1;
    }

    /**
     * @return int
     */
    public final int next() {
        if (rowSetList == null || rowSetList.size() == 0) return -1;
        int rowCount = rowSetList.size();
        int rowIndex = currentRowIndex + 1;
        if (rowIndex < rowCount)
            return this.goToRow(rowIndex);
        else
            return -1;
    }

    /**
     * @return int
     */
    public final int last() {
        if (rowSetList == null || rowSetList.size() == 0) return -1;
        int rowIndex = rowSetList.size() - 1;
        return this.goToRow(rowIndex);
    }

    /**
     * @param rowSet ESPRowSet
     * @return int
     */
    public int goToRow(ESPRowSet rowSet) {
        if (rowSetList == null || rowSetList.size() == 0) return -1;
        int index = rowSetList.indexOf(rowSet);
        if (index != -1) {
            return goToRow(index);
        }
        return -1;
    }

    /**
     * @param rowIndex int
     * @return int
     */
    public int goToRow(int rowIndex) {
        if (rowSetList == null || rowSetList.size() == 0) return -1;
        if (rowIndex < 0 || rowIndex >= rowSetList.size()) return -1;
        int oldIndex = 0;
        if (currentRowIndex != rowIndex) {
            oldIndex = currentRowIndex;
            currentRowIndex = rowIndex;
            // 产生游标移动事件
            fireCursorChange(oldIndex, currentRowIndex);
        }
        return currentRowIndex;
    }

    /**
     * @param rowIndex int
     * @return int
     */
    public int goToRowNoWithCursorEvent(int rowIndex) {
        if (rowSetList == null || rowSetList.size() == 0) return -1;
        if (rowIndex < 0 || rowIndex >= rowSetList.size()) return -1;
        int oldIndex = 0;
        if (currentRowIndex != rowIndex) {
            oldIndex = currentRowIndex;
            currentRowIndex = rowIndex;
            // 不产生游标移动事件
            // fireCursorChange(oldIndex,currentRowIndex);
        }
        return currentRowIndex;
    }

    /**
     * @return ESPRowSet
     */
    public EFRowSet getRowSet() {
        if (rowSetList == null || rowSetList.size() == 0) return null;
        if (currentRowIndex < 0 || currentRowIndex >= rowSetList.size()) return null;
        return (EFRowSet) rowSetList.get(currentRowIndex);
    }

    /**
     * @param rowIndex int
     * @return EFRowSet
     */
    public EFRowSet getRowSet(int rowIndex) {
        if (rowSetList == null || rowSetList.size() == 0) return null;
        if (rowIndex < 0 || rowIndex >= rowSetList.size()) return null;
        return (EFRowSet) rowSetList.get(rowIndex);
    }

    /**
     *
     */
    protected transient int currentRowIndex = 0;

//  protected java.util.List<EFRowSet> rowSetArray = null;

    /**
     * @return List
     */
    public java.util.List getRowSetArray() {
        if (rowSetList == null || rowSetList.size() == 0) return null;
        java.util.List arrayList = new java.util.ArrayList();
        arrayList.addAll(rowSetList);
        return arrayList;
    }

    /**
     *
     */
    public void setRowSetArray(java.util.List list) {
        if (list == null || list.size() == 0) {
            rowSetList = null;
            return;
        }
        rowSetList = new Vector<ESPRowSet>();
        rowSetList.addAll(list);
    }

    /**
     *t
     */
    private Vector<ESPRowSet> rowSetList = null;

    /**
     * @return the rowSetList
     */
    public List<ESPRowSet> getRowSetList() {
        return rowSetList;
    }

    /**
     * @return int
     */
    public int getRowCount() {
        if (rowSetList == null) return 0;
        return rowSetList.size();
    }

    /**
     * @param rowSetList the rowSetList to set
     */
    public void setRowSetList(Vector<ESPRowSet> rowSetList) {
        this.rowSetList = rowSetList;
        setChildMasterKey();
    }

    public void setDataSetType(int dataSetType) {
        this.dataSetType = dataSetType;
    }

    /**
     * @param rowSet
     */
    public void insertRowSet(ESPRowSet rowSet) {
        if (rowSetList == null) {
            rowSetList = new Vector<ESPRowSet>();
        }
        rowSet.setMasterKey(master);
        int index = currentRowIndex == -1 ? rowSetList.size() + 1 : currentRowIndex + 1;
        insertRowSet(index, rowSet);
    }

    /**
     * @param rowSet ESPRowSet
     * @param unique boolean
     */
    public void insertRowSet(ESPRowSet rowSet, boolean unique) {
        if (rowSetList == null) {
            rowSetList = new Vector<ESPRowSet>();
        }
        rowSet.setMasterKey(master);
        int index = currentRowIndex == -1 ? rowSetList.size() + 1 : currentRowIndex + 1;
        insertRowSet(index, rowSet, unique);
    }

    /**
     * @param rowSet ESPRowSet
     */
    public void addRowSet(ESPRowSet rowSet) {
        int index = 0;
        if (rowSetList != null) index = rowSetList.size() + 1;
        insertRowSet(index, rowSet);
    }

    /**
     * @param rowSet ESPRowSet
     */
    public void appendRowSet(ESPRowSet rowSet) {
        int index = 0;
        if (rowSetList != null) index = rowSetList.size() + 1;
        insertRowSet(index, rowSet);
    }

    /**
     * @param index  int
     * @param rowSet ESPRowSet
     */
    public void insertRowSet(int index, ESPRowSet rowSet) {
        insertRowSet(index, rowSet, false);
//    if (rowSetList == null) {
//      rowSetList = new Vector<ESPRowSet> ();
//    }
//    // 插入前面一行
//    if(index <=rowSetList.size()){
//      if (index > 0) index--;
//      rowSetList.insertElementAt(rowSet, index);
//    } else {
//      rowSetList.add(rowSet);
//    }
//    rowSet.setMasterKey(master);
//    // 创建主键索引
//    buildPrimeKeyIndex(rowSet);
//    fireTableRowsInserted(index, index);
//    // 增加到
//    rowSet.insertDataSetManager(this);
    }

    /**
     * @param index  int
     * @param rowSet ESPRowSet
     * @param unique boolean
     */
    public void insertRowSet(int index, ESPRowSet rowSet, boolean unique) {
        if (rowSetList == null) rowSetList = new Vector<ESPRowSet>();
        // 主键唯一
        if (unique && containsKey(getPrimeKeyValue(rowSet)))
            return;
        // 插入前面一行
        if (index < rowSetList.size()) {//<=改的
            if (index > 0) index--;
            rowSetList.insertElementAt(rowSet, index);
        } else {
            rowSetList.add(rowSet);
        }
        rowSet.setMasterKey(master);
        // 创建主键索引
        buildPrimeKeyIndex(rowSet);
        fireTableRowsInserted(index, index, rowSet);
        // 增加到
        rowSet.insertDataSetManager(this);
        rowSet.setDataSet(this);
    }

    /**
     * @param key String
     * @return boolean
     */
    public boolean containsKey(String key) {
        if (primeKey == null || key == null || primeKeyRowSetMap == null) return false;
        return primeKeyRowSetMap.containsKey(key);
    }

    /**
     * @param firstRow int
     * @param lastRow  int
     */
    public void fireTableRowsInserted(int firstRow, int lastRow, ESPRowSet ers) {
        DataSetEvent dse = new DataSetEvent(this, firstRow, lastRow,
                DataSetEvent.ALL_COLUMNS, DataSetEvent.INSERT);
        dse.setEventRowSet(ers);
        fireDataSetEvent(dse);
    }

    /**
     * @param row int
     * @return ESPRowSet
     */
    public ESPRowSet removeRowSet(int row) {
        if (row == -1 || row >= rowSetList.size()) return null;
        ESPRowSet rowSet = rowSetList.remove(row);
        if (rowSet != null) {
            String primeKeyValue = getPrimeKeyValue(rowSet);
            if (primeKeyRowSetMap != null)
                primeKeyRowSetMap.remove(primeKeyValue);
            fireTableRowsDeleted(row, row, rowSet);
            rowSet.removeDataSetManager(this);
        }
        // 删除后，可能需要修改当前行索引
        if (this.currentRowIndex >= rowSetList.size()) {
            this.goToRow(rowSetList.size() - 1);
        }
        return rowSet;
    }

    /**
     * @param rowSet RowSet
     * @return RowSet
     */
    public ESPRowSet removeRowSet(ESPRowSet rowSet) {
        if (rowSetList == null) return null;
        int index = rowSetList.indexOf(rowSet);
        return removeRowSet(index);
    }

    /**
     * @param firstRow int
     * @param lastRow  int
     */
    public void fireTableRowsDeleted(int firstRow, int lastRow, ESPRowSet ers) {
        DataSetEvent dse = new DataSetEvent(this, firstRow, lastRow,
                DataSetEvent.ALL_COLUMNS, DataSetEvent.DELETE);
        dse.setEventRowSet(ers);
        if (firstRow > 0)
            dse.setNewCursor(firstRow - 1);
        fireDataSetEvent(dse);
    }

    /**
     *
     */
    protected Map<String, ESPRowSet> primeKeyRowSetMap = null;

    public void setPrimeKeyRowSetMap(Map<String, ESPRowSet> primeKeyRowSetMap) {
        this.primeKeyRowSetMap = primeKeyRowSetMap;
    }

    /**
     * @return Map
     */
    public Map<String, ESPRowSet> getPrimeKeyRowSetMap() {
        return primeKeyRowSetMap;
    }

    public int getCurrentRowIndex() {
        return currentRowIndex;
    }


    public void buildPrimeKeyIndex() {
        if (rowSetList == null || primeKey == null) {
            return;
        }
//    primeKeyRowSetMap = new java.util.HashMap<String, ESPRowSet> ();
        primeKeyRowSetMap = new ConcurrentHashMap<String, ESPRowSet>();
        ESPRowSet rowSet = null;
        for (int i = 0; i < rowSetList.size(); i++) {
            rowSet = rowSetList.get(i);
            String primeKeyValue = getPrimeKeyValue(rowSet);
            if (primeKeyValue != null) {
                primeKeyRowSetMap.put(primeKeyValue, rowSet);
            }
            //KEYKEYKEY
            buildPrimeKeyKeyIndex(rowSet);
        }
    }

    /**
     * @param rowSet ESPRowSet
     */
    public void buildPrimeKeyIndex(ESPRowSet rowSet) {
        if (primeKey == null || rowSet == null) return;
        if (primeKeyRowSetMap == null)
            primeKeyRowSetMap = new ConcurrentHashMap<String, ESPRowSet>();
        String primeKeyValue = getPrimeKeyValue(rowSet);
        if (primeKeyValue != null)
            primeKeyRowSetMap.put(primeKeyValue, rowSet);
        //KEYKEYKEY
        buildPrimeKeyKeyIndex(rowSet);
    }

    /**
     * @param rowSet RowSet
     * @return String
     */
    public String getPrimeKeyValue(ESPRowSet rowSet) {
        if (primeKey == null || primeKey.length == 0) return null;
        String value = "";
        for (int i = 0; i < primeKey.length; i++) {
            value += (((i == 0) ? "" : "-") + rowSet.getString(primeKey[i], ""));
        }
        return value;
    }

    /**
     * @param keyValue String[]
     * @return String
     */
    protected String getPrimeKeyValue(String[] keyValue) {
        String value = "";
        for (int i = 0; i < keyValue.length; i++) {
            value += (((i == 0) ? "" : "-") + (keyValue[i] == null ? "" : keyValue[i]));
        }
        return value;
    }

    /**
     * @param keyValue String[]
     * @return RowSet
     */
    public ESPRowSet getRowSet(String[] keyValue) {
        if (primeKeyRowSetMap == null) return null;
        return primeKeyRowSetMap.get(getPrimeKeyValue(keyValue));
    }

    public ESPRowSet getRowSet(String keyValue) {
        String[] keys = keyValue.split(",");
        return getRowSet(keys);
    }

    public EFRowSet getCurrentRowSet() {
        return getRowSet0();
    }

    public EFRowSet getRowSet0() {
        if (rowSetList == null || rowSetList.size() == 0) return null;
        if (this.currentRowIndex < 0 || this.currentRowIndex >= rowSetList.size()) return null;
        return (EFRowSet) rowSetList.get(this.currentRowIndex);
    }


    /**
     * @param o Object
     */
    public void setMasterKey(Object o) {
        if (master != o) {
            master = o;
            setChildMasterKey();
        }
    }

    /**
     *
     */
    private void setChildMasterKey() {
        for (int i = 0; rowSetList != null && i < rowSetList.size(); i++) {
            ESPRowSet es = rowSetList.get(i);
            es.setMasterKey(master);
        }
    }

    /**
     * @return Object
     */
    public Object getMasterKey() {
        return master;
    }

    /**
     *
     */
    public void activeDataSet() {
        if (this.currentRowIndex == -1)
            this.first();
        else
            fireCursorChange(currentRowIndex, currentRowIndex);
    }

    /**
     *
     */
    protected void fireCursorChange(int oldIndex, int newIndex) {
        DataSetEvent dse = new DataSetEvent(this, DataSetEvent.CURSOR);
        dse.setOldCursor(oldIndex);
        dse.setNewCursor(newIndex);
        dse.setEventRowSet(this.getRowSet(newIndex)); // 设置当前事件的RowSet
        fireDataSetEvent(dse);
    }

    /**
     * @param e DataSetEvent
     */
    public void fireDataSetEvent(final DataSetEvent e) {
        if (listenerList == null) return;
        // 如果没有设置当前行索引，则找出来
        if (e.getNewCursor() == -1) {
            int index = this.rowSetList.indexOf(e.getEventRowSet());
            e.firstRow = index;
            e.lastRow = index;
        }

        for (int i = 0; i < listenerList.size(); i++) {
            DataSetListener listener = listenerList.get(i);
            listener.dataSetChanged(e);
        }
    }

    /**
     *
     */
    protected transient List<DataSetListener> listenerList = null;

    /**
     * @param l DataSetListener
     */
    public void addDataSetListener(DataSetListener l) {
        if (listenerList == null) listenerList = new ArrayList<DataSetListener>();
        listenerList.add(l);
    }

    /**
     * Removes a listener from the list that's notified each time a
     * change to the data model occurs.
     *
     * @param l the TableModelListener
     */
    public void removeDataSetListener(DataSetListener l) {
        if (listenerList == null) return;
        listenerList.remove(l);
    }

    /**
     * @return DataSetListener[]
     */
    public DataSetListener[] getTableModelListeners() {
//    if ( listenerList == null ) return null;
//    return (DataSetListener[])listenerList.getListeners(
//        DataSetListener.class);
        return null;
    }

    /**
     * @param listenerType Class
     * @return T[]
     */
    public <T extends EventListener> T[] getListeners(Class<T> listenerType) {
//    if ( listenerList == null ) return null;
//    return listenerList.getListeners(listenerType);
        return null;
    }

    /**
     *
     */
    protected transient java.util.Map filterDataSetMap = null;

    /**
     * @param cont    String
     * @param dataSet EFDataSet
     */
    public void putFilterDataSet(String cont, EFDataSet dataSet) {
        if (filterDataSetMap == null) filterDataSetMap = new ConcurrentHashMap();
        filterDataSetMap.put(cont, dataSet);
        // 设置监听器
        //  dataSet.listenerList = this.listenerList;
    }

    /**
     * @param cont String
     * @return EFDataSet
     */
    public EFDataSet getFilterDataSet(String cont) {
        if (filterDataSetMap == null) return null;
        return (EFDataSet) filterDataSetMap.get(cont);
    }

    /**
     * @return EFDataSet
     */
    public EFDataSet getSelectedDataSet() {
        if (this.rowSetList == null || this.rowSetList.size() == 0) return null;
        EFDataSet dataSet = null;
        EFRowSet rowSet = null;
        for (int i = 0; i < rowSetList.size(); i++) {
            rowSet = (EFRowSet) rowSetList.get(i);
            if (rowSet.isRowSelected()) {
                if (dataSet == null)
                    dataSet = EFDataSet.getInstance(this.getTableName(), _DATA_SET_MAP_);
                dataSet.addRowSet(rowSet);
            }
        }
        return dataSet;
    }

    /**
     * @param i1 int
     * @param i2 int
     */
    public void swapEFRowSet(int i1, int i2) {
        EFRowSet rs1 = getRowSet(i1);
        EFRowSet rs2 = getRowSet(i2);
        getRowSetList().set(i1, rs2);
        getRowSetList().set(i2, rs1);
    }

    /**
     * 多主键的情况下，记录多个主键之间的关系
     */
    protected Map<String, Map> primeKeyKeyMap = null;

    public Map<String, Map> getPrimeKeyKeyMap() {
        return primeKeyKeyMap;
    }

    public void setPrimeKeyKeyMap(Map<String, Map> primeKeyKeyMap) {
        this.primeKeyKeyMap = primeKeyKeyMap;
    }

    /**
     *
     */
    public void buildPrimeKeyKeyIndex(ESPRowSet rowSet) {
        String[] primeKey = getPrimeKey();
        String key = null, val = null;
        java.util.Map<String, java.util.List> map = null;
        java.util.List<String> list = null;
        for (int i = 0; primeKey != null && i < primeKey.length; i++) {
            map = getPrimeKeyKeyMap(primeKey[i]);
            key = rowSet.getString(primeKey[i], "");
            val = getPrimeKeyValue(rowSet);
            if (map == null || val == null) continue;
            list = map.get(key);
            if (list == null) {
                list = new ArrayList<String>();
                map.put(key, list);
            }
            if (!list.contains(val))
                list.add(val);
        }
    }

    /**
     * 根据关键字枚举关键值
     *
     * @param keys String[]
     * @return List
     */
    public java.util.List<String[]> listPrimeValByKey(String[] keys) {
        if (primeKey == null || keys == null) return null;
        for (int i = 0; keys != null && i < keys.length; i++) {
            if (!java.util.Arrays.asList(primeKey).contains(keys[i]))
                return null;
        }
        if (primeKeyRowSetMap == null)
            primeKeyRowSetMap = new ConcurrentHashMap();
        java.util.List<String[]> keyValList = new ArrayList<String[]>();
        java.util.List<String> tmpKeyValStr = new ArrayList<String>();
        Object[] keyVals = primeKeyRowSetMap.keySet().toArray();
        for (int i = 0; keyVals != null && i < keyVals.length; i++) {
            String keyVal = (String) keyVals[i];
            // 和primeKey的索引一致
            String[] vals = com.efounder.pub.util.StringFunction.split(keyVal, "-");
            String[] data = new String[keys.length];
            String tmpKey = "";
            for (int j = 0; keys != null && j < keys.length; j++) {
                int index = java.util.Arrays.asList(primeKey).indexOf(keys[j]);
                if (index < 0 || index >= vals.length) continue;
                data[j] = vals[index];
                tmpKey += vals[index];
                if (j > 0) tmpKey += "-";
            }
            // 值重复的只放一遍
            if (!tmpKeyValStr.contains(tmpKey)) {
                tmpKeyValStr.add(tmpKey);
                keyValList.add(data);
            }
        }
        return keyValList;
    }

    /**
     * @param primeKey    String
     * @param primeKeyVal String
     * @return String[]
     */
    public java.util.List<String> getPrimeKeyByKey(String primeKey, String primeKeyVal) {
        java.util.Map map = getPrimeKeyKeyMap(primeKey);
        return (java.util.List<String>) map.get(primeKeyVal);
    }

    /**
     * @param keys String[]
     * @param vals String[]
     * @return List
     */
    public java.util.List<String> getPrimeKeyByKey(String[] keys, String[] vals) {
        if (keys == null || vals == null || keys.length != vals.length) return null;
        java.util.List lists = new java.util.ArrayList();
        for (int i = 0; keys != null && i < keys.length; i++) {
            lists.add(getPrimeKeyByKey(keys[i], vals[i]));
        }
        // return DataSetUtils.intersectList(lists);
        return null;
    }

    /**
     * @param primeKey    String
     * @param primeKeyVal String
     * @return EFDataSet
     */
    public EFDataSet getDataSetByKey(String primeKey, String primeKeyVal) {
        EFDataSet eds = EFDataSet.getInstance(getTableName(), EFDataSet._DATA_SET_VIEW_);
        eds.setPrimeKey(this.getPrimeKey());
        java.util.List<String> list = getPrimeKeyByKey(primeKey, primeKeyVal);
        for (int i = 0; list != null && i < list.size(); i++) {
            eds.insertRowSet(getRowSet(list.get(i)));
        }
        return eds;
    }

    /**
     * @param keys String[]
     * @param vals String[]
     * @return EFDataSet
     */
    public EFDataSet getDataSetByKey(String[] keys, String[] vals) {
        EFDataSet eds = EFDataSet.getInstance(getTableName(), EFDataSet._DATA_SET_VIEW_);
        eds.setPrimeKey(this.getPrimeKey());
        java.util.List<String> list = getPrimeKeyByKey(keys, vals);
        for (int i = 0; list != null && i < list.size(); i++) {
            eds.insertRowSet(getRowSet(list.get(i)));
        }
        return eds;
    }

    /**
     * @param primeKey String
     * @return int
     */
    public int getPrimeKeyIndex(String primeKey) {
        if (getPrimeKey() == null) return -1;
        return Arrays.asList(getPrimeKey()).indexOf(primeKey);
    }

    /**
     * @param primeKey String
     * @return Map
     */
    public java.util.Map getPrimeKeyKeyMap(String primeKey) {
        if (primeKeyKeyMap == null) primeKeyKeyMap = new ConcurrentHashMap<String, Map>();
        if (primeKeyKeyMap.get(primeKey) == null) {
//      HashMap<String, java.util.List<String>> map = new HashMap<String, java.util.List<String>> ();
            java.util.Map<String, java.util.List<String>> map = new ConcurrentHashMap<String, java.util.List<String>>();
            primeKeyKeyMap.put(primeKey, map);
        }
        return primeKeyKeyMap.get(primeKey);
    }

    public void RemoveObject(String key) {
        int count = this.getRowCount();
        for (int i = 0; i < count; i++) {
            this.getRowSet(i).putObject(key, null);
        }
    }

    public String toString() {
//        String aa = super.toString();
//        if (this.getRowCount() > 0)
//            aa += " rows:" + getRowCount();
//        return aa;
        return "";
    }

    /**
     * @param dataSet EFDataSet
     */
    public void addAll(EFDataSet dataSet) {
        boolean add = dataSet != null && dataSet.getRowCount() > 0;
        for (int i = 0; dataSet != null && i < dataSet.getRowCount(); i++) {
            EFRowSet rowSet = dataSet.getRowSet(i);
            addRowSet(rowSet);
        }
        if (add && this.getPrimeKey() != null) this.buildPrimeKeyIndex();
    }

    protected transient java.util.List childRowSet = null;

    protected void insertChildRowSet(EFRowSet rowSet) {
        if (childRowSet == null) childRowSet = new java.util.ArrayList();
        if (childRowSet.indexOf(rowSet) == -1)
            childRowSet.add(rowSet);
    }

    protected EFRowSet removeChildRowSet(EFRowSet rowSet) {
        if (childRowSet == null) return null;
        if (childRowSet.remove(rowSet))
            return rowSet;
        return null;
//    return (EFRowSet)childRowSet.remove(rowSet);
    }

    // add by skyline 2011/12/15
    protected EFDataSet hierarchyDataSet = null;

    public EFDataSet getHierarchyDataSet() {
        return hierarchyDataSet;
    }

    public void setHierarchyDataSet(EFDataSet ds) {
        hierarchyDataSet = ds;
    }

    //已删除行的记录<key:主键, value:EFRowSet>
    protected Map<String, EFRowSet> deletedRowsMap = null;

    public Map<String, EFRowSet> getDeletedRowsMap() {
        return deletedRowsMap;
    }

    public void setDeletedRowsMap(Map<String, EFRowSet> deletedRowsMap) {
        this.deletedRowsMap = deletedRowsMap;
    }

    //add by wujf 2012/02/25
    private java.util.Map<String, EFDataSet> dataSetMap = null;

    public java.util.Map<String, EFDataSet> getDataSetMap() {
        return dataSetMap;
    }

    public void setDataSetMap(java.util.Map<String, EFDataSet> dsm) {
        dataSetMap = dsm;
    }

    /**
     * @param dsType String
     * @return EFDataSet
     */
    public EFDataSet getDataSet(String dsType) {
        if (dataSetMap == null) return null;
        return dataSetMap.get(dsType);
    }

    /**
     * @param dsType  String
     * @param dataSet EFDataSet
     */
    public void setDataSet(String dsType, EFDataSet dataSet) {
        if (dataSetMap == null) dataSetMap = new java.util.HashMap<String, EFDataSet>();
        dataSetMap.put(dsType, dataSet);
    }

    /**
     * @param F_Gn    int
     * @param dataSet EFDataSet
     */
    public void setLimitDataSet(int F_Gn, EFDataSet dataSet) {
        String key = "F_G" + F_Gn;
        setDataSet(key, dataSet);
    }

    /**
     * @param F_Gn int
     * @return EFDataSet
     */
    public EFDataSet getLimitDataSet(int F_Gn) {
        String key = "F_G" + F_Gn;
        return getDataSet(key);
    }
}
